In collaboration with Juthi Dewan, Sam Ding, and Vichy Meas, we designed this project for our Bayesian Statistics course taught by Dr. Alicia Johnson. We’d like to extend our thanks to Alicia for guiding us through Bayes and the capstone experience!
A reproducible version of this blog post with all code can be found here.
We were initially interested in characterizing New York City’s internal racial dynamics using demography, geographic mobility, community health, and economic outcomes. As this project developed, we found ourselves thinking about the relationships between transportation (in)access and housing inequity. In our project, there are two major sections: Subway Accessibility and Transportation and Structural Inequity. In Subway Accessibility we explore transportation deserts and what are the major determinants of Subway Inaccess in New York City using two Bayesian classification models. While in Transportation and Structural Inequity, we extend our discussion of transportation access to study its relationship to both rental prices and evictions using Bayesian multivariable regression.
First, however, let’s do a data introduction:
# Load packages
library(tidyverse)
library(janitor)
library(here)
library(rstan)
library(rstanarm)
library(bayesrules)
library(tidyverse)
library(rstanarm)
library(broom.mixed)
library(tidybayes)
library(bayesplot)
library(bayesrules)
library(tidyverse)
library(rstanarm)
library(broom.mixed)
library(tidybayes)
library(forcats)
library(bayesplot)
library(sf)
library(nycgeo)
library(tidycensus)
library(extrafont)
library(extrafontdb)
# themes
theme_set(theme_minimal())
brown_green <- c("#E9DBC2","#7D9B8A","#4D6F5C","#D29B5B","#744410","#1C432D")
color_scheme_set(brown_green)
nyc_join <- merge(nta_sf,nta_acs_data)
nyc_join <- nyc_join %>%
st_transform(., crs=4269)
county_list <- nyc_join %>% pull(county_name) %>% unique()
census_api_key("0cc07f06386e317f312adef5e0892b0d002b7254")
census_data <- get_acs(state = "NY",
county = c(county_list),
geography = "tract",
variables = c(gini_inequality ="B19083_001"),
year = 2019,
output = "wide",
survey = "acs5",
geometry = TRUE) %>%
dplyr::select(-c(NAME, ends_with("M"))) %>%
rename_at(vars(ends_with("E")), .funs = list(~str_sub(., end = -2))) %>%
st_transform(., 4269) %>%
dplyr::select(-GEOID)
vari_names <- read_csv(here("clean_data", "nyc_names_vichy_complied2.csv"))
nyc_clean <- st_read(here("clean_data", "nyc_data_vichy_complied2.shp"))
colnames(nyc_clean) <- colnames(vari_names)
gini_neighborhood <- st_join(nyc_clean, census_data, left = TRUE) %>%
group_by(nta_id) %>%
summarize(gini_neighborhood=median(gini_inequality, na.rm=T)) %>%
as.tibble() %>%
dplyr::select(nta_id, gini_neighborhood)
nyc_clean <- nyc_clean %>%
as.tibble() %>%
left_join(., gini_neighborhood, by="nta_id")%>%
unique() %>%
st_as_sf()
nyc_compiled <- nyc_clean %>%
mutate(asian_perc = asian_count / total_pop) %>%
mutate(white_perc = white_count / total_pop) %>%
mutate(black_perc = black_count / total_pop) %>%
mutate(latinx_perc = latinx_count / total_pop) %>%
mutate(native_perc = native_count / total_pop) %>%
mutate(noncitizen_perc = noncitizen_count / total_pop) %>%
mutate(evictions_perc = eviction_count / total_pop) %>%
mutate(uninsured_perc = uninsured_count / total_pop) %>%
mutate(unemployment_perc = unemployment_count / total_pop) %>%
mutate(below_poverty_line_perc = below_poverty_line_count / total_pop) %>%
mutate(transportation_desert_4cat =
factor(transportation_desert_4cat, levels=c("Poor", "Limited", "Satisfactory", "Excellent")))
All data used in this project are from two major sources: the Tidycensus package and NYC Open Data.
Tidycensus is an R package interface, developed by Kyle Walker and Matt Herman, that enables easy access to the US Census Bureau’s data APIs and returns Tidyverse-ready data frames from various major US Census Bureau datasets. Our demographic and socioeconomic data are drawn from the 2019 American Community Survey results found in Tidycensus package. A summary of our ACS data variables is below:
borough: NYC Boroughtotal_pop: Total Population Count by Census Tractmean_income: Mean Income by Census Tractbelow_poverty_line_count: Number of People Living Below the 100% Poverty Line by Census Tractmean_rent: Mean Rent by Censusunemployment_count: Number of People on Unemployment by Census Tractlatinx_count: Number of Latinx People by Census Tractwhite_count: Number of White People by Census Tractblack_count: Number of Black People by Census Tractnative_count: Number of Native People by Census Tractasian_count: Number of Asian People by Census Tractnaturalized_citizen_count: Number of Naturalized Citizens by Census Tractnoncitizen_count: Number of Foreign Born People by Census Tractuninsured_count: Number of Uninsured Citizens of any Age by Census Tractgini_neighborhood : Income inequality measured by the Gini Index per Census TractNote that these predictors are all measured at the census level. To aggregate these estimates at the neighborhood level, we performed two transformations:
Then, for count based demographic predictors, we divide by the total population in each neighborhood to define scaled demographic metrics. They are as follows:
asian_perc: Percentage of Asian Peoplewhite_perc: Percentage of White Peopleblack_perc: Percentage of Black Peoplelatinx_perc: Percentage of Latinx Peoplenative_perc: Percentage of Native Peoplenoncitizen_perc: Percentage of Foreign Born Peopleuninsured_perc: Percentage of Uninsured Citizens of any Ageunemployment_perc: Percentage of People on Unemploymentbelow_poverty_line_perc: Percentage of people living below the 100% poverty line.We used NYC’s Open Data portal and the Baruch College GIS Lab to collect information on the remaining predictors. In particular, we used geotagged locations of Subway Stops, Bus Stops, Grocery Stores, Schools, and Evictions from the Departments of Transportation, Health, Education, and Housing, respectively, to calculate the following variables:
school_count: Public school countseviction_count: Eviction countsstore_count: Grocery store and food vendor countssub_count: Subway station countsbus_count: Bus station countsperc_covered_by_transit: Percent of Neighborhood Within Walking Distance (.5 miles) of Any Subway Stop.transportation_desert_4cat: Subway Accessibility (Poor, Limited, Satisfactory, Excellent)The process involved grouping geotagged locations by the defined neighborhood boundary regions in R’s SF package and ArcGIS. We will detail the process of identifying subway deserts in the “Subway Deserts” section.
We present a numeric summary on our data with 224 observations of 38 variables below. However, note that we use percent equivalents for most demographic count variables.
#summary(modeling_data)
library(table1)
table_print <- table1(~
total_pop + mean_income + mean_rent +
gini_neighborhood +
below_poverty_line_perc +
eviction_count +
transportation_desert_4cat +
noncitizen_perc + white_perc + black_perc +
latinx_perc + asian_perc
| borough, data = nyc_compiled %>% as_tibble()) %>% as_tibble()
colnames(table_print) <- c("Variable", "Bronx (N=44)", "Brooklyn (N=64)","Manhattan (N=39)", "Queens (N=77)", "Overall (N=224)")
library(kableExtra)
table_print%>%
filter(Variable!="") %>% kable() %>% kable_styling() %>% scroll_box(height ="400px", width="100%")
| Variable | Bronx (N=44) | Brooklyn (N=64) | Manhattan (N=39) | Queens (N=77) | Overall (N=224) |
|---|---|---|---|---|---|
| total_pop | |||||
| Mean (SD) | 30200 (18700) | 37800 (24600) | 38300 (24600) | 25900 (20900) | 32300 (22800) |
| Median [Min, Max] | 29800 [0, 69200] | 38300 [0, 97800] | 35700 [0, 95300] | 25000 [0, 87700] | 31600 [0, 97800] |
| mean_income | |||||
| Mean (SD) | 43400 (17900) | 69600 (28700) | 103000 (49700) | 74500 (14400) | 71900 (33900) |
| Median [Min, Max] | 38000 [23100, 94200] | 61200 [27400, 148000] | 108000 [33300, 212000] | 72600 [37500, 104000] | 67200 [23100, 212000] |
| Missing | 8 (18.2%) | 9 (14.1%) | 6 (15.4%) | 19 (24.7%) | 42 (18.8%) |
| mean_rent | |||||
| Mean (SD) | 1230 (197) | 1580 (465) | 1960 (674) | 1650 (198) | 1600 (465) |
| Median [Min, Max] | 1240 [833, 1620] | 1450 [792, 3280] | 2070 [884, 3270] | 1630 [1140, 2250] | 1510 [792, 3280] |
| Missing | 8 (18.2%) | 9 (14.1%) | 6 (15.4%) | 19 (24.7%) | 42 (18.8%) |
| gini_neighborhood | |||||
| Mean (SD) | 0.467 (0.0317) | 0.462 (0.0292) | 0.516 (0.0379) | 0.423 (0.0260) | 0.459 (0.0439) |
| Median [Min, Max] | 0.467 [0.407, 0.519] | 0.466 [0.382, 0.515] | 0.525 [0.436, 0.582] | 0.420 [0.358, 0.484] | 0.457 [0.358, 0.582] |
| below_poverty_line_perc | |||||
| Mean (SD) | 0.251 (0.122) | 0.197 (0.143) | 0.168 (0.129) | 0.119 (0.0832) | 0.179 (0.128) |
| Median [Min, Max] | 0.251 [0, 0.444] | 0.179 [0, 1.00] | 0.126 [0, 0.576] | 0.103 [0, 0.615] | 0.148 [0, 1.00] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
| eviction_count | |||||
| Mean (SD) | 438 (340) | 245 (234) | 223 (233) | 126 (131) | 238 (255) |
| Median [Min, Max] | 406 [1.00, 1130] | 163 [1.00, 829] | 152 [1.00, 1120] | 93.0 [1.00, 521] | 148 [1.00, 1130] |
| transportation_desert_4cat | |||||
| Poor | 2 (4.5%) | 5 (7.8%) | 0 (0%) | 32 (41.6%) | 39 (17.4%) |
| Limited | 18 (40.9%) | 19 (29.7%) | 4 (10.3%) | 30 (39.0%) | 71 (31.7%) |
| Satisfactory | 4 (9.1%) | 10 (15.6%) | 5 (12.8%) | 5 (6.5%) | 24 (10.7%) |
| Excellent | 20 (45.5%) | 30 (46.9%) | 30 (76.9%) | 10 (13.0%) | 90 (40.2%) |
| noncitizen_perc | |||||
| Mean (SD) | 0.174 (0.0936) | 0.150 (0.132) | 0.139 (0.0506) | 0.174 (0.101) | 0.160 (0.103) |
| Median [Min, Max] | 0.169 [0, 0.581] | 0.127 [0, 1.00] | 0.133 [0, 0.242] | 0.143 [0, 0.471] | 0.143 [0, 1.00] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
| white_perc | |||||
| Mean (SD) | 0.114 (0.163) | 0.381 (0.277) | 0.454 (0.268) | 0.287 (0.247) | 0.309 (0.270) |
| Median [Min, Max] | 0.0313 [0, 0.606] | 0.385 [0, 1.00] | 0.496 [0, 0.829] | 0.247 [0, 1.00] | 0.222 [0, 1.00] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
| black_perc | |||||
| Mean (SD) | 0.301 (0.185) | 0.292 (0.308) | 0.146 (0.179) | 0.178 (0.273) | 0.231 (0.261) |
| Median [Min, Max] | 0.274 [0.0631, 0.833] | 0.152 [0, 1.00] | 0.0585 [0.00873, 0.591] | 0.0406 [0, 0.899] | 0.121 [0, 1.00] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
| latinx_perc | |||||
| Mean (SD) | 0.531 (0.197) | 0.190 (0.163) | 0.246 (0.206) | 0.255 (0.178) | 0.292 (0.221) |
| Median [Min, Max] | 0.618 [0, 0.784] | 0.143 [0, 0.808] | 0.170 [0.0608, 0.724] | 0.217 [0, 0.856] | 0.203 [0, 0.856] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
| asian_perc | |||||
| Mean (SD) | 0.0370 (0.0496) | 0.108 (0.121) | 0.127 (0.116) | 0.241 (0.190) | 0.138 (0.156) |
| Median [Min, Max] | 0.0179 [0, 0.217] | 0.0733 [0, 0.472] | 0.113 [0, 0.661] | 0.205 [0, 0.757] | 0.0777 [0, 0.757] |
| Missing | 3 (6.8%) | 6 (9.4%) | 3 (7.7%) | 15 (19.5%) | 27 (12.1%) |
We found that Manhattan had the largest population counts, highest mean rental prices, highest mean income, highest income inequality (e.g. gini value), most number of neighborhoods with excellent subway access, and the greatest proportion of white citizens.
Conversely, we observed that the Bronx has the lowest mean income and highest eviction counts, while having the highest proportions of people living below the poverty line, and the highest number of people with limited subway access. Importantly, the Bronx also had the highest densities of both Latinx and Black residents of any other borough in New York, meaning that the Black and Latinx residents in New York are experiencing the burden of New York’s structural inequities.
We will touch on the connections between demographics, transportation access, and housing more explicitly in the following sections.
New York City is the most populous city in the US with more than 8.8 million people. To support the daily commutes of its residents, NYC also built the New York City Subway, the oldest, longest, and currently busiest subway system in the US, averaging approximately 5.6 million daily rides on weekdays and a combined 5.7 million rides each weekend.
Compared to other US cities where automobiles are the most popular mode of transportation (ahem, Minneapolis), only 32% of NYC’s population chooses to commute by cars. NYC’s far-reaching transit system is then unique, given that more than 70% of the population commute by cars in other metropolitan areas.
Despite having the most extensive transit network in the entire US, NYC is still lacking in terms of transit accessibility for some neighborhoods. The general consensus in academia is that residents who walk more than 0.5 miles to get to reliable transit are considered lacking transportation access, or residing in a transportation desert. For our research, we adopted this concept to study these gaps in transportation access. Specifically, we attempt to identify and study “Subway Deserts”.
Extending the USDA’s definition of a food desert, we define subway deserts as the percentage of a neighborhood— or any arbitrary geographic area— that is within walking distance of any subway stop. Citing the U.S. Federal Highway Administration, we defined walking distance as a 0.5 mile radius and computed these regions in ArcGIS. We chose subway stations because of the subway’s reliable frequency, high connectivity between boroughs, and high ridership per vehicle. Our argument against including the number of bus stops in our calculations of transportation access is that the quantity of bus stops does not accurately imply public transport accessibility due to the variability in bus efficiency, punctuality, and use. A major limitation of our work was the omission of Staten Island because it is not connected to any other borough by subway. Rather, Staten Island users typically drive or train into the city. Further, we felt that the inclusion of Staten Island would mischaracterize the relationship between lacking access and not needing access since Staten Island is an overwhelmingly white, wealthy, borough that has high levels of car ownership.
We first geocoded subway stop locations in NYC from the NYC Department of Transportation. Then, using ArcGIS we created a 0.5-mile-radius buffer for each station and calculated what percent of each neighborhood was covered by a buffer region. We display an example below.
A nice image.
In the graph, buffer zones are in light pink with overlapping boundaries dissolved between stations, while the dark pink dots indicate the exact geographic locations of the stations. Each neighborhood, then, had a percentage score that defined it’s subway accessibility score.
Upon observation, we categorized the areas served by the subway network into four ordinal categories: Poor, Limited, Satisfactory, and Excellent. These categories are defined at 0-1%, 1-75%, 75-90%, and 90-100% of area covered by transit, respectively. We defined these cutoffs using the distribution of subway coverage percentages and our own judgment on what constitutes a desert. As such, these cutoffs are specific to New York City and may not be perfectly reproducible. The following plot details the spatial locations of these transportation categories.
nyc_compiled %>%
ggplot() +
geom_sf(aes(fill = transportation_desert_4cat), color = "#8f98aa") +
scale_fill_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"),
guide = guide_legend(title = "Accessibility:"), na.value="#D6D6D6") +
theme_minimal() +
ggtitle("Subway Accessibility in NYC")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_legend(title = "Acessibility", title.position="top", title.hjust = 0.5))
In the following two subsections, we describe how we understood and classified transportation deserts using two models.
Naive Bayes Model is one of the most popular models for classifying a response variable with 2 or more categories.
We implemented a naive Bayes classifier on subway access because it is both computationally efficient and applicable to Bayesian classification settings where outcomes may have 2+ categories. Specifically, we fit transportation access by taking mean_income, percentage below the poverty line, and the number of grocery stores. Because we are predicting 4 levels of transportation access, we initially fit this model using the e1071 package to classify subway transit level.
library(e1071)
nyc_naive <- read_csv(here("clean_data", "nyc_names_vichy_complied2.csv"))%>%
mutate(transportation_desert_4cat = factor(transportation_desert_4cat, levels=c("Poor", "Limited", "Satisfactory", "Excellent"))) %>%
mutate(transportation_desert_4num = factor(as.numeric(transportation_desert_4cat))) %>%
mutate(asian_perc = (asian_count / total_pop) * 100) %>%
mutate(white_perc = (white_count / total_pop)* 100) %>%
mutate(black_perc = (black_count / total_pop)* 100) %>%
mutate(latinx_perc = (latinx_count / total_pop)* 100) %>%
mutate(native_perc = (native_count / total_pop)* 100) %>%
mutate(below_poverty_perc = (below_poverty_line_count / total_pop) * 100) %>%
mutate(noncitizen_perc = (noncitizen_count / total_pop)* 100) %>%
mutate(evictions_perc = (eviction_count / total_pop)* 100) %>%
mutate(uninsured_perc = (uninsured_count / total_pop)* 100) %>%
mutate(unemployment_perc = (unemployment_count / total_pop)* 100) %>%
filter(nta_type == 0)
set.seed(454)
naive_model <- naiveBayes(transportation_desert_4cat ~
mean_income +
below_poverty_perc +
store_count,
data = nyc_naive)
naive2_prediction <- naive_classification_summary_cv(naive_model,
nyc_naive,
y="transportation_desert_4cat", k=10)$cv
naive2_prediction %>%
kable(align = "c", caption = "Naive Model - Summary") %>%
kable_styling()
| transportation_desert_4cat | Poor | Limited | Satisfactory | Excellent |
|---|---|---|---|---|
| Poor | 70.83% (17) | 25.00% (6) | 0.00% (0) | 4.17% (1) |
| Limited | 28.85% (15) | 44.23% (23) | 0.00% (0) | 26.92% (14) |
| Satisfactory | 5.00% (1) | 40.00% (8) | 0.00% (0) | 55.00% (11) |
| Excellent | 8.33% (7) | 27.38% (23) | 0.00% (0) | 64.29% (54) |
Under 10-fold cross validation, our Naive Bayes model had an overall cross-validated accuracy of 51.11%. However, our predictions were most accurate when predicting Poor transportation access (78.12%) and Excellent transportation access (72.62%). The following plot describes the cross-validated accuracy breakdown by each observed transportation access category.
prediction <- as.data.frame(naive2_prediction) %>%
pivot_longer(
cols= Poor:Excellent,
names_to = 'Predictions',
values_to = 'Probability'
) %>%
mutate(Probability = as.numeric(str_extract(Probability,'\\d+\\.\\d+'))/100) %>%
mutate(transportation_desert_4cat = factor(transportation_desert_4cat, levels=c("Poor", "Limited", "Satisfactory", "Excellent"))) %>%
mutate(Predictions = factor(Predictions, levels=c("Poor", "Limited", "Satisfactory", "Excellent")))
prediction %>%
ggplot(aes(x=transportation_desert_4cat, y=Probability, fill=Predictions)) +
geom_bar(position="fill", stat="identity") +
scale_y_continuous(labels = seq(0, 100, by = 25)) +
labs(title="Accessibility Predictions by Observed Category", y="Proportion", x="")+
theme(panel.grid.major.x = element_line("transparent"),
# axis.text.y.left = element_blank(),
axis.text.x.bottom = element_text(size = 12, face = "bold"),
plot.title = element_text(size = 20, hjust=.5, face = "bold", family="DIN Condensed")) +
scale_fill_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"),
guide = guide_legend(title = "Subway Accessibility \nCategory"), na.value="#D6D6D6")
From the plot, it is clear that our naive Bayes model is sufficient when predicting the extrema of subway (in)access given the overwhelming proportion of true-poor and true-excellent classifications. However, it remains imperfect when considering the inaccuracy for both the limited and satisfactory transportation categories, our data’s distributions, and its interpretability.
Importantly, naive Bayes assumes that all quantitative predictors are normally distributed within each Y category and further it assumes (i.e. that predictors are independent within each Y category). Our data do not meet these assumptions, unfortunately. Further, naive Bayes is a blackbox classifier. That is, naive Bayes classification might give us accurate predictions, but it doesn’t give us a sense of where these predictions come from or subway access is related to the predictors.
Having realized the shortcomings of the naive Bayes model, we wanted to see if there are any alternatives. We land on the ordinal regression model.
library(rsample)
set.seed(454)
nyc_compiled_classify <- nyc_compiled %>%
mutate(transportation_desert_4cat = factor(transportation_desert_4cat, levels=c("Poor", "Limited", "Satisfactory", "Excellent"))) %>%
mutate(transportation_desert_4num = factor(as.numeric(transportation_desert_4cat))) %>%
mutate(asian_perc = (asian_count / total_pop) * 100) %>%
mutate(white_perc = (white_count / total_pop)* 100) %>%
mutate(black_perc = (black_count / total_pop)* 100) %>%
mutate(latinx_perc = (latinx_count / total_pop)* 100) %>%
mutate(native_perc = (native_count / total_pop)* 100) %>%
mutate(below_poverty_perc = (below_poverty_line_count / total_pop) * 100) %>%
mutate(noncitizen_perc = (noncitizen_count / total_pop)* 100) %>%
mutate(uninsured_perc = (uninsured_count / total_pop)* 100) %>%
mutate(unemployment_perc = (unemployment_count / total_pop)* 100) %>%
filter(nta_type == 0) %>%
as.tibble()
data_split <- initial_split(nyc_compiled_classify, prop = .8)
data_train <- training(data_split)
data_test <- testing(data_split)
model2 <- stan_polr(as.factor(transportation_desert_4num) ~ mean_income + below_poverty_line_perc + store_count,
data =data_train, prior_counts = dirichlet(1),
prior=R2(0.5), iter=500, seed = 86437, refresh=0, prior_PD=FALSE)
tidy(model2, effects = "fixed", conf.int = TRUE, conf.level = 0.8) %>%
mutate(term = case_when(
term == "1|2" ~ "Poor | Limited",
term == "2|3" ~ "Limited | Satisfactory",
term == "3|4" ~ "Satisfactory | Excellent",
TRUE ~ term
))%>%
kable(align = "c", caption = "Ordinal Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| mean_income | 0.0000446 | 0.0000101 | 0.0000326 | 0.0000578 |
| below_poverty_line_perc | 17.3415852 | 3.5554437 | 12.7085829 | 22.2958048 |
| store_count | 0.0190357 | 0.0050905 | 0.0123953 | 0.0265525 |
| Poor | Limited | 4.8823426 | 1.2302915 | 3.3631402 | 6.5114280 |
| Limited | Satisfactory | 7.0074877 | 1.2895602 | 5.3420571 | 8.7955688 |
| Satisfactory | Excellent | 7.6748663 | 1.2936117 | 5.9871445 | 9.4438596 |
Then using a function written by Connie Zhang, we describe the accuracy of the ordinal model below.
ordinal_accuracy<-function(post_preds,mydata){
post_preds<-as.data.frame(post_preds)
results<-c()
for (j in (1:length(post_preds))){
results[j]<-as.numeric(tail(names(sort(table(post_preds[,j]))))[4])
}
results<-as.data.frame(results)
compare<-cbind(results,mydata$transportation_desert_4num)
compare<-compare %>%mutate(results=as.numeric(results))
compare<-compare %>% mutate(`mydata$transportation_desert_4num`=as.numeric(`mydata$transportation_desert_4num`))
compare<-compare %>%mutate(accuracy=ifelse(as.numeric(results)==as.numeric(`mydata$transportation_desert_4num`),1,0))
print(sum(compare$accuracy)/length(post_preds))
}
nyc_compiled[is.na(nyc_compiled)] = 0
set.seed(86437)
my_prediction2 <- posterior_predict(
model2,
newdata = data_test)
ordinal_accuracy(my_prediction2, data_test)
## [1] 0.6666667
my_prediction2 <- posterior_predict(
model2,
newdata = data_test)
prediction_long <- my_prediction2 %>%
t() %>%
as.tibble() %>%
mutate_if(is.character, as.numeric) %>%
rownames_to_column() %>%
rowwise(id=rowname) %>%
summarize(median=ifelse(mean(c_across(where(is.numeric)))>3.5, ceiling(mean(c_across(where(is.numeric)))), floor(mean(c_across(where(is.numeric)))))) %>%
rename(predicted_desert = median)%>%
mutate(predicted_desert = case_when(
predicted_desert==1 ~ "Poor",
predicted_desert ==2 ~ "Limited",
predicted_desert ==3 ~ "Satisfactory",
TRUE ~ "Excellent",
)) %>%
mutate(predicted_desert = factor(predicted_desert, levels=c("Poor", "Limited", "Satisfactory", "Excellent")))
data_test %>%
dplyr::select(nta_id, borough, transportation_desert_4cat) %>%
rownames_to_column() %>%
left_join(., prediction_long, by="rowname") %>%
ggplot(aes(x=transportation_desert_4cat, fill=predicted_desert)) +
geom_bar(position="fill")+
scale_y_continuous(labels = seq(0, 100, by = 25)) +
labs(title="Accessibility Predictions by Observed Category", y="Proportion", x="")+
theme(panel.grid.major.x = element_line("transparent"),
# axis.text.y.left = element_blank(),
axis.text.x.bottom = element_text(size = 12, face = "bold"),
plot.title = element_text(family="DIN Condensed", size =20, hjust=.5, face = "bold")) +
scale_fill_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"),
guide = guide_legend(title = "Subway Accessibility \nCategory"), na.value="#D6D6D6")
Transportation access is a pervasive structural issue. However, previous research on transportation access has demonstrated that many of these gaps in access also deepen the chasms of racial and class-based inequity. In this analysis, it seemed that low-income and racialized— typically Black and Latinx— communities were most likely to confront transportation inequities. Additionally, we have observed that predominantly Black and Latinx neighborhoods in the Bronx faced some of the highest rates of eviction, likely indicating that these inequities may overlap.
This next section aims to connect transportation access to housing-inequities that we know also have racial and class dimensions. In particular, we wanted to assess transportation access’s relationship with immigrant community size, rental prices, and eviction counts .
desert_map <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = transportation_desert_4cat), color = "#8f98aa") +
scale_fill_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"), na.value="#D6D6D6") +
theme_minimal() +
ggtitle("Subway Access ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_legend(title = "Acessibility", title.position="top", title.hjust = 0.5))
rent_map <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = mean_rent), color = "#8f98aa") +
scale_fill_gradient(low = "#FCF5EE", high = "#30969C") +
theme_minimal() +
ggtitle("Mean Rent ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Dollars", title.position="top", title.hjust = 0.5))
evict <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = eviction_count), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#C47572") +
theme_minimal() +
ggtitle("Eviction Counts ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Number of Evictions", title.position="top", title.hjust = 0.5))
noncit <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = noncitizen_perc), color = "#8f98aa") +
scale_fill_gradient(low = "#FCF5EE", high = "#5E76AD") +
theme_minimal() +
ggtitle("Immigrant Density ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Percent Non-Citizen", title.position="top", title.hjust = 0.5))
library(egg)
ggarrange(desert_map, rent_map, evict, noncit,
ncol=2, nrow=2)
Transportation access is typically worst in areas with the highest densities of non-citizen residents, while it is the best in neighborhoods with the highest mean rental prices. Further, observe that eviction counts are highly concentrated in north and south NYC, where some of these neighborhoods have mixed-accessibility to transit.
Unfortunately, rent, transportation access, and eviction counts may also be associated with respective density of nonwhite communities.
white <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = white_perc), color = "#8f98aa") +
scale_fill_gradientn(colors = c("#FCF5EE","#919BB6", "#5A6687", "#3D465C")) +
theme_minimal() +
ggtitle("White Population ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Percent White", title.position="top", title.hjust = 0.5))
black <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = black_perc), color = "#8f98aa") +
scale_fill_gradientn(colors = c("#FCF5EE","#F8ABA6", "#F58581", "#DB3F37")) +
theme_minimal() +
ggtitle("Black Population ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Percent Black", title.position="top", title.hjust = 0.5))
asian <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = asian_perc), color = "#8f98aa") +
scale_fill_gradientn(colors = c("#FCF5EE","#C1C5EC", "#A1A8E2", "#4451C5"),
guide = guide_colourbar(title = "Percent Asian")) +
theme_minimal() +
ggtitle("Asian Population ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Percent Asian", title.position="top", title.hjust = 0.5))
latinx <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot() +
geom_sf(aes(fill = latinx_perc), color = "#8f98aa")+
scale_fill_gradientn(colors = c("#FCF5EE","#F4E2B8", "#E9C572", "#E77E2F")) +
theme_minimal() +
ggtitle("Latinx Population ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Percent Latinx", title.position="top", title.hjust = 0.5))
ggarrange(desert_map, white, black, latinx, asian, ncol=3, nrow=2)
From the plots, neighborhoods with the highest densities of Black and Asian community members also have the poorest scores of subway access, while the converse holds true for neighborhoods with the highest proportion of White residents.
Further, observe that eviction counts are most common in neighborhoods with the highest densities of Black and Latinx community members. The below faceted visualizations detail the specific relationships between the proportion of Black, Latinx, Asian, and White residents in a neighborhood with eviction counts.
black_eviction <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=black_perc,
color=transportation_desert_4cat,
y=eviction_count)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Eviction Counts by Black Density \nper Transportation Category", y="", x="Black (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 30 ,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
asian_eviction <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=asian_perc,
color=transportation_desert_4cat,
y=eviction_count)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Eviction Counts by Asian Density \nper Transportation Category", y="", x="Asian (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 30,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
latinx_eviction <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=latinx_perc,
color=transportation_desert_4cat,
y=eviction_count)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Eviction Counts by Latinx Density \nper Transportation Category", y="", x="Latinx (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 30,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
white_eviction <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=white_perc,
color=transportation_desert_4cat,
y=eviction_count)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Eviction Counts by White Density \nper Transportation Category", y="", x="White (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 30,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
ggarrange(black_eviction, latinx_eviction, asian_eviction, white_eviction, ncol=2, nrow=2)
Black and Latinx residential proportions are associated with increased eviction counts. However, we must specify that Black resident proportions are uniformly associated with increases in eviction counts across transportation levels, while the relationship between eviction counts and Latinx resident proportion is not. In contrast, both White and Asian proportions are uniformly associated with decreases in eviction counts.
Lastly, let’s consider mean neighborhood rental prices. The following visualizations detail the relationships between the proportion of Black, Latinx, Asian, and White residents in a neighborhood with that neighborhood mean rental price.
black_rent <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=black_perc,
color=transportation_desert_4cat,
y=mean_rent)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Neighborhood Rental Price Averages \nby Black Density per Transportation Category", y="", x="Black (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size =25,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
asian_rent <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=asian_perc,
color=transportation_desert_4cat,
y=mean_rent)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Neighborhood Rental Price Averages \nby Asian Density per Transportation Category", y="", x="Asian (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 25,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
latinx_rent <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=latinx_perc,
color=transportation_desert_4cat,
y=mean_rent)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Neighborhood Rental Price Averages \nby Latinx Density per Transportation Category", y="", x="Latinx (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 25,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
white_rent <- nyc_compiled %>%
filter(nta_type == 0) %>%
ggplot(aes(x=white_perc,
color=transportation_desert_4cat,
y=mean_rent)) +
geom_point(size=2)+
geom_smooth(aes(group=transportation_desert_4cat),span = 1, size=3, se=F)+
labs(title="Neighborhood Rental Price Averages \nby White Density per Transportation Category", y="", x="White (%)")+
theme_linedraw()+
theme(legend.position = "none",
# axis.text.y.left = element_blank(),
# axis.text.x.bottom = element_text(size = 16, face = "bold"),
plot.title = element_text(family="DIN Condensed", size = 25,hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 14,
color = "White",
face = "bold")) +
scale_color_manual(values=c("#895F32","#E9DBC2","#7D9B8A", "#395645"))+ facet_wrap(.~transportation_desert_4cat, scales = "free")
ggarrange(black_rent, latinx_rent, asian_rent, white_rent, ncol=2, nrow=2)
Increases in White-resident proportions were uniformly associated with increases in average neighborhood rental prices across all transportation access categories. The converse is true for the relationship between Black and Latinx neighborhood densities and rental prices. It then seems that despite living in cheaper neighborhoods, both NYC’s Black and Latinx communities are carrying the largest burden of eviction.
Our next section details the statistical models we used to better characterize the clear relationships between housing inequities, urban racism, and transportation access.
In order to understand the respective distributions of immigrant population size, evictions, and mean rental prices in NYC, we fit 3 non-hierarchical Bayesian models with each variable as an outcome. In the following section, we fit hierarchical regression models with similar likelihood and prior structure. However, in those models neighborhood values are grouped by borough.
We list our non-hierarchical models and their predictors below:
transportation_desert_4cat, borough, total_pop, gini_neighborhood, mean_income, mean_rent, unemployment_perc, black_perc, latinx_perc, asian_perc$x_1, x_2, ..., x_{14}$transportation_desert_4cat, borough, gini_neighborhood, mean_income, black_perc, latinx_perc, asian_perc, below_poverty_line_perc,school_count,store_count$x_1, x_2, ..., x_{14}$transportation_desert_4cat, borough, total_pop, below_poverty_line_perc, gini_neighborhood, mean_income, mean_rent, black_perc, latinx_perc, asian_perc$x_1, x_2, ..., x_{14}$Because there are four levels of both transportation_desert_4cat and borough, stan_glm defines $x_1, \dots, x_3$ and $x_5, \dots, x_7$ as dummy variables of each respective predictor’s categories, with one common reference category for our intercept.
Across all models we specified weakly-informative normal priors for the $\beta_{k}$s associated with each predictor \(X_{k}\). However, there are differences in terms of model specifications that we outline below:
For 1 and 3, we used weakly informative normal priors on all predictors and the intercept, then allowed stan_glm to estimate initial priors. This decision was ultimately due to our unfamiliarity with NYC’s history of evictions and non-citizen population and what their relationships to our predictors may be.
We fit parallels of 1 and 3 that both had a Poisson likelihood, as opposed to a Negative Binomial likelihood in previous iterations of this report. However, we observed an inconsistent spread of variance and increased 0 counts in both the eviction and immigrant count data. Because stan_glm does not have a zero-inflated poisson distribution, we ultimately performed two Negative-Binomial regressions. Further discussions of our Poisson regressions have been removed from this project.
For 2, we also used weakly informative normal priors on all predictors. However, we specified a normal prior with $\mu = 600$ and $\sigma = 20$ for the scaled intercept of mean rental prices.
Our model specifications are detailed in the following subsections
modeling_data <- nyc_compiled %>%
mutate(black_perc = black_perc * 10) %>%
mutate(white_perc = white_perc * 10) %>%
mutate(latinx_perc = latinx_perc * 10) %>%
mutate(asian_perc = asian_perc * 10) %>%
mutate(native_perc = native_perc * 10) %>%
mutate(unemployment_perc = unemployment_perc * 5) %>%
mutate(uninsured_perc = uninsured_perc * 5) %>%
mutate(mean_income = mean_income / 100) %>%
mutate(mean_rent = mean_rent / 100) %>%
filter(nta_type==0) %>%
mutate(nta_type = as.factor(nta_type)) %>%
mutate(borough = as.factor(borough))
noncit_model <- stan_glm(
noncitizen_count ~
transportation_desert_4cat +
borough + total_pop + gini_neighborhood +
mean_income + mean_rent + unemployment_perc +
black_perc + latinx_perc + asian_perc,
data = modeling_data,
family = neg_binomial_2,
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Non-Citizen Count}_{i} \mid \beta_{0c}, \beta_1, ..., \beta_k, r & \sim \text{NegBin}(\mu_i, r) \; \; \; \text{where } \log(\mu_i) = \beta_{0c} + \sum^{14}_{k=1} \beta_{k}X_{ik} \\ \beta_{0c} &\sim N(0,2.5^2)\\ r &\sim \text{Exp}(1)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &5.5004, 7.9328, 4.9972, 5.4697, 6.443, 5.3347, .0001, \\ &56.9002, 0.0074, 0.5699, 39.9937, 0.993, 1.142, 1.6003 \} \end{align} $$
pp_check(noncit_model)+
xlab("Non-Citizen Count") +
labs(title = "Negative Binomial Model of \nImmigrant/Non-Citizen Count")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
It seems that our simulations (light green) of non-citizen count distributions were largely consistent across our iterations. However, our simulations were strongly biased from the observed non-citizen counts where we would typically predict smaller non-citizen counts more frequently. Additionally, it seemed that variance between simulations increased as non-citizen counts increased. Acknowledging these trends, our negative-binomial model seems to be a pretty good distributional fit, but could certainly be improved upon!
rent_model <- stan_glm(
mean_rent ~
transportation_desert_4cat + borough + gini_neighborhood +
mean_income + black_perc + latinx_perc + asian_perc+
below_poverty_line_perc + school_count + store_count,
data = modeling_data,
family = gaussian,
prior_intercept = normal(1600 , 20),
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Mean Rental Price}_{i} \mid \beta_{0c}, \beta_1, ..., \beta_k, r & \sim N(\mu_i, \sigma^2) \; \; \; \; \text{where } \mu_i = \beta_{0c} + \sum^{14}_{k=1} \beta_{k}X_{ik} \\ \beta_{0c} &\sim N(1600,20^2)\\ \sigma &\sim \text{Exp}(0.23)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &24.1301 34.8009 21.9225 23.9953 28.2651 23.4030 249.6185 \\ & 0.0325 4.3562 5.0098 7.0204 110.1265 1.7160 0.2803 \} \end{align} $$
Once again note that we are specifying the parameters of our scaled intercept prior, $\beta_{0c}$, so that the the typical mean neighborhood rental price $\sim $N(1600,20^2)$, while our priors for the \(\beta_k\) are weakly-informed negative priors. We chose our prior intercept specifications of mean rental price ($\beta_{0c}$) using Juthi’s experience renting in NYC and a group conversation about typical rental prices we would elect to pay in NYC, Los Angeles, and other major cities we have lived in or around. However, we decided to continue using weakly-informative normal priors for the predictors because we were unsure about their relationship— if any— to rental prices.
pp_check(rent_model)+
xlab("Mean Rental Price") +
labs(title = "Normal Model of \nMonthly Mean Rental Price")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
Our simulations are relatively consistent. However, these simulated distributions are much more variable than the simulated distributions we saw in our non-citizen rent model. Importantly, it also seems our simulated normal posterior distributions had higher variance than what was observed and that is likely because the mean rental prices themselves are not perfectly normally distributed. Theoretically, we could change our likelihood model to adjust for the skew, but for now this is good!
eviction_model <- stan_glm(
eviction_count ~
transportation_desert_4cat + borough + total_pop +
below_poverty_line_perc + gini_neighborhood + mean_income + mean_rent+
black_perc + latinx_perc + asian_perc,
data = modeling_data,
family = neg_binomial_2,
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Eviction Count}_{i} \mid \beta_{0c}, \beta_1, ..., \beta_k, r & \sim \text{NegBin}(\mu_i, r) \; \; \; \text{where } \log(\mu_i) = \beta_{0c} + \sum^{14}_{k=1} \beta_{k}X_{ik} \\ \beta_{0c} &\sim N(0,2.5^2)\\ r &\sim \text{Exp}(1)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &5.5004, 7.9328, 4.9972, 5.4697, 6.443, 5.3347, .0001, \\ &25.1032, 56.9002, 0.0074, 0.5699, 0.993, 1.142, 1.6003 \} \end{align} $$
pp_check(eviction_model)+
xlab("Eviction Count") +
xlim(0,2000)+
labs(title = "Negative Binomial Model of \nEviction Count")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
Our simulations of eviction count distributions are dramatically consistent across the iterations. Further, our simulations were relatively consistent with the observed eviction counts. Our negative-binomial model seems to be a pretty good distributional fit, but could certainly be improved upon!
non_citizen_clean <- modeling_data %>%
na.omit()%>%
arrange(noncitizen_count)
list <- non_citizen_clean %>%
arrange(noncitizen_count)
set.seed(84735)
predictions_non_citizen <- posterior_predict(
noncit_model, newdata = non_citizen_clean)
ppc_intervals_grouped(
y = list$noncitizen_count,
group = list$borough,
yrep = predictions_non_citizen,
prob_outer = 0.8,
facet_args=list(scales="free_x")) +
scale_x_continuous(
labels = list$nta_id,
breaks = 1:nrow(list)) +
labs(x = "Neighborhood", y = "Non-Citizen Count")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
The above posterior prediction intervals plot the observed non-immigrant count in a New York residential neighborhood in one of the five boroughs. We faceted by borough to see if there were systematic biases in our predictions that would make our analyses inapplicable to a particular borough. For the most part, our predictions seem good! However, it seems that the observed counts are closest to our posterior prediction prediction medians in Queens and Brooklyn and that our observed counts move away from the posterior prediction means and either into the 50% and 80% credible intervals as eviction counts increase.
tidy(noncit_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
mutate(estimate= ifelse(term == "(Intercept)", exp(estimate), (exp(estimate)-1)*100),
conf.low= ifelse(term == "(Intercept)", exp(conf.low), (exp(conf.low)-1)*100),
conf.high = ifelse(term == "(Intercept)", exp(conf.high), (exp(conf.high)-1)*100))%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Non-Citizen Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 586.3350650 | 0.5892081 | 279.4142986 | 1225.6561984 |
| transportation_desert_4catLimited | 41.8934646 | 0.0947005 | 25.5731268 | 61.1029809 |
| transportation_desert_4catSatisfactory | 47.4693053 | 0.1247702 | 25.5040878 | 72.5540766 |
| transportation_desert_4catExcellent | 50.7372290 | 0.1130738 | 29.6651683 | 74.9662615 |
| total_pop | 0.0025227 | 0.0000016 | 0.0023118 | 0.0027338 |
| mean_income | -0.0771135 | 0.0002473 | -0.1084767 | -0.0474758 |
| mean_rent | 6.2804740 | 0.0171488 | 3.9676947 | 8.6757882 |
| black_perc | 5.6497441 | 0.0162756 | 3.5018528 | 7.8785025 |
| latinx_perc | 13.0729744 | 0.0233917 | 9.7224158 | 16.4053482 |
| asian_perc | 21.2545862 | 0.0254210 | 17.2637303 | 25.3869183 |
Limited Subway Access: When controlling for all other predictors, a neighborhood with limited transit access is expected to have approximately 21.82% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (7.48%, 38.27%) non citizen residents, indicating that neighborhoods with limited transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Satisfactory Subway Access: When controlling for all other predictors, a neighborhood with satisfactory transit access is expected to have approximately 30.22% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (13.99%, 49.09%) non citizen residents, indicating that neighborhoods with satisfactory transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Excellent Subway Access: When controlling for all other predictors, a neighborhood with excellent transit access is expected to have approximately 29.84% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (13.34%, 48.51%) non citizen residents, indicating that neighborhoods with excellent transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Brooklyn: When controlling for all other predictors, a neighborhood in Brooklyn is expected to have approximately 16.61% more non-citizens than a neighborhood in the Bronx. There’s an 80% probability that this increase could lie anywhere between (1.68%, 34.07) non citizen residents, indicating that neighborhoods in Brooklyn almost certainly have more non citizen residents than the Bronx, but the magnitude of this increase may vary.
Manhattan: When controlling for all other predictors, a neighborhood in Manhattan is expected to have approximately 20.58% more non-citizens than in the Bronx. There’s an 80% probability that this increase could lie anywhere between (2.268, 42.85) non citizen residents, indicating that neighborhoods in Manhattan almost certainly have more non citizen residents than the Bronx.
Mean Income: When controlling for all other predictors, a 100 dollar increase in mean neighborhood income is associated with approximately a 0.0793% decrease in non citizen count. However, there is a 80% chance that the decrease in non citizen count may be any value between (0.1102, 0.0476), indicating that there is almost certainly a negative relationship between mean income and non citizen count, but its magnitude may vary.
Mean Rent: When controlling for all other predictors, a 100 dollar increase in mean neighborhood rent is associated with approximately a 6.29% increase in non citizen counts. However, there is an 80% chance that the increase in non citizen count may be any value between (3.96%, 8.68%), indicating that there is almost certainly a positive relationship between mean rent and non citizen count, but its magnitude may vary.
Black Percentage: When controlling for all other predictors, a 10% increase in the Black population in a neighborhood is associated with approximately a 5.20% increase in non citizen counts. However, there is an 80% chance that the increase in non citizen count may be any value between (2.99%, 7.45%), indicating that there is almost certainly a positive relationship between Black resident percentage and non citizen count, but its magnitude may vary.
Latinx Percentage: When controlling for all other predictors, a 10% increase in the Latinx population in a neighborhood is associated with approximately a 13.46% increase in non citizen count. However, there is an 80% chance that the increase in non citizen count may be any value between (10.08%, 17.07%), indicating that there is almost certainly a positive relationship between Latinx resident percentage and non citizen count, but its magnitude may vary.
Asian Percentage: When controlling for all other predictors, a 10% increase in the Asian population in a neighborhood is associated with approximately a 19.63% increase in non citizen count. However, there is an 80% chance that the increase in non citizen count may be any value between (15.75%, 23.69%), indicating that there is almost certainly a positive relationship between Asian resident percentage and non citizen count, but its magnitude may vary.
rent_clean <- modeling_data %>%
na.omit()%>%
arrange(mean_rent)
list <- rent_clean %>%
arrange(mean_rent)
set.seed(84735)
predictions_rent <- posterior_predict(
rent_model, newdata = rent_clean)
ppc_intervals_grouped(
y = list$mean_rent,
group = list$borough,
yrep = predictions_rent,
prob_outer = 0.8,
facet_args=list(scales="free_x")) +
scale_x_continuous(
labels = list$nta_id,
breaks = 1:nrow(list)) +
labs(x = "Neighborhood", y = "Mean Rental Price (100$)")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
The above posterior prediction intervals plot the typical rental prices observed in New York’s residential neighborhoods across the five boroughs. For the most part, our predictions seem really consistent! However, the coverage of our posterior predictive intervals in Brooklyn and Queens looks the best.
tidy(rent_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Rent Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 7.1907523 | 2.6731333 | 3.8938421 | 10.6049863 |
| transportation_desert_4catSatisfactory | 0.7344379 | 0.5658431 | 0.0176256 | 1.4751197 |
| mean_income | 0.0123246 | 0.0007862 | 0.0113456 | 0.0133216 |
| asian_perc | 0.2324910 | 0.1121342 | 0.0840456 | 0.3787778 |
| school_count | -0.0412700 | 0.0277610 | -0.0761378 | -0.0050853 |
For rent model:
Store Count: When controlling for all other predictors, as grocery store and food vendor counts in a neighborhood increase by 1, rent increases by approximately $1.049 dollars. However, there is a 80% chance that the increase associated with store count may be any value between (0.307, 1.799) dollars, indicating that there is almost certainly a positive relationship between store count and rent, but its magnitude may vary slightly.
Mean Income: When controlling for all other predictors, a 100 dollar increase in mean neighborhood income is associated with approximately a $1.20 increase in rent. However, there is a 80% chance that the increase associated with rental price increases may be any value between (1.129, 1.284) dollars, indicating that there is almost certainly a positive relationship between mean income and mean rental prices, but its magnitude may vary slightly.
Black Percentage: When controlling for all other predictors, a 10% increase in the black proportion of a neighborhood is associated with approximately a $10.20 decrease in rent. However, there is an 80% chance that the decrease associated with rent may be any value between (19.36, 0.685) dollars, indicating that there is almost certainly a negative relationship between black resident percentage and rent, but its magnitude may vary.
Asian Percentage: When controlling for all other predictors, a 10% increase in the Asian population in a neighborhood is associated with approximately a $20.52 increase in rent. However, there is an 80% chance that the increase associated with rent may be any value between (5.763, 34.87), indicating that there is almost certainly a positive relationship between Asian resident percentage and rent, but its magnitude may vary greatly.
eviction_clean <- modeling_data %>%
na.omit()%>%
arrange(eviction_count)
list <- eviction_clean %>%
as.tibble() %>%
arrange(eviction_count)
set.seed(454)
predictions_eviction <- posterior_predict(
eviction_model, newdata = eviction_clean)
ppc_intervals_grouped(
y = list$eviction_count,
group = list$borough,
yrep = predictions_eviction,
prob_outer = 0.8,
facet_args=list(scales="free")) +
scale_x_continuous(
labels = eviction_clean$nta_id,
breaks = 1:nrow(eviction_clean)) +
labs(x = "Neighborhood", y = "Eviction Counts")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
tidy(eviction_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
mutate(estimate= ifelse(term == "(Intercept)", exp(estimate), (exp(estimate)-1)*100),
conf.low= ifelse(term == "(Intercept)", exp(conf.low), (exp(conf.low)-1)*100),
conf.high = ifelse(term == "(Intercept)", exp(conf.high), (exp(conf.high)-1)*100))%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Eviction Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 18.9606336 | 0.6693084 | 7.9440877 | 44.343760 |
| transportation_desert_4catLimited | 55.5749368 | 0.1112790 | 35.3397986 | 79.706230 |
| transportation_desert_4catSatisfactory | 60.0247265 | 0.1367452 | 34.7136480 | 91.532347 |
| transportation_desert_4catExcellent | 60.5375408 | 0.1276609 | 35.9026953 | 89.249159 |
| boroughBrooklyn | -40.6015422 | 0.1246683 | -49.2407395 | -30.543618 |
| boroughManhattan | -23.4506537 | 0.1465118 | -36.7021113 | -7.242022 |
| boroughQueens | -31.3881544 | 0.1264226 | -41.7372764 | -18.972115 |
| total_pop | 0.0022258 | 0.0000019 | 0.0019843 | 0.002463 |
| gini_neighborhood | 1434.4584788 | 1.3802922 | 154.3828616 | 9188.911169 |
| mean_income | -0.1242914 | 0.0003219 | -0.1653685 | -0.083784 |
| mean_rent | 4.4053031 | 0.0199378 | 1.7724588 | 7.037090 |
| black_perc | 18.2082002 | 0.0192147 | 15.4945685 | 21.083031 |
| latinx_perc | 7.6568548 | 0.0309493 | 3.4538193 | 11.870799 |
After removing predictors whose 80% credible intervals included the possibility of non-effect when controlling for other covariates, we found that there were 13 remaining predictors of an arbitrary neighborhood’s eviction counts. In the following list, categorical predictors’ classes were listed together:
In the following section, we interpret each predictor. However, we included total population to control for eviction count’s incidence relative to neighborhood population. As such, we will not interpret its specific \(\beta\) value.
Next, we interpret each predictor:
We also fit 3 Bayesian hierarchical models similar to those in the previous section. Now, however, we let borough be a natural grouping variable of our data. Note that prior distributions for predictors’ associated \(\beta\) values and the data are the same.
We list our hierarchical models and their predictors below:
transportation_desert_4cat, total_pop, gini_neighborhood, mean_income, mean_rent, unemployment_perc, black_perc, latinx_perc, asian_percboroughtransportation_desert_4cat, gini_neighborhood, mean_income, black_perc, latinx_perc, asian_perc, bus_count,school_count,store_count, noncitizen_percboroughtransportation_desert_4cat, total_pop, gini_neighborhood, mean_income, mean_rent, black_perc, latinx_perc, asian_perc, bus_count,store_count,unemployment_perc, uninsured_percboroughAgain for 1 and 3, we used weakly informative priors and allowed stan_glm to estimate initial priors. This decision was ultimately due to our unfamiliarity with NYC’s history of evictions and non-citizen population. For Model 2, we specified a normal prior with mean 1600 and standard deviation at 20 using previous experience as renters both in NYC and other comparable major cities. Across all count models, we fit both Poisson and Negative-Binomial likelihood distributions for the observed eviction and non-citizen counts. However, we observed an inconsistent spread of variance and increased 0 counts in both the eviction and immigrant count data. As such, we felt that a Negative-Binomial distribution was more appropriate for both data.
Our model specifications are detailed in the following subsections
hi_noncit_model <- stan_glmer(
noncitizen_count ~
transportation_desert_4cat +
total_pop + gini_neighborhood +
mean_income + mean_rent + unemployment_perc +
black_perc + latinx_perc + asian_perc + (1|borough),
data = modeling_data,
family = neg_binomial_2,
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Non-Citizen Count}_{ij} \mid \beta_{0}, \beta_1, ..., \beta_k, r & \sim \text{NegBin}(\mu_{ij}, r) \; \; \; \text{where } \log(\mu_{ij}) = \beta_{0j} + \sum^{11}_{k=1} \beta_{k}X_{ijk} \\ \beta_{0j}\mid \beta_{0}, \sigma_0 & \stackrel{ind}{\sim} N(\beta_0, \sigma_0^2)\\ \beta_{0c} &\sim N(0, 2.5^2) \\ r &\sim \text{Exp}(1)\\ \sigma_0 &\sim \text{Exp}(1)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &5.5004, 7.9328, 4.9972, .0004, 56.9002,\\ & 0.0074, 0.5699, 39.9937, 0.993, 1.142, 1.6003\} \end{align} $$
pp_check(hi_noncit_model)+
xlab("Non-Citizen Count") +
labs(title = "Hierarchical Negative Binomial Model of \nImmigrant/Non-Citizen Count")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
It seems that our simulations of non-citizen count distributions in the hierarchical model were largely consistent across the iterations. Similar to the non-hierarchical model, our simulations are biased away from the observed non-citizen counts as our model predicts a higher number of non-citizens more frequently.
hi_rent_model <- stan_glmer(
mean_rent ~
transportation_desert_4cat + gini_neighborhood +
mean_income + black_perc + latinx_perc + asian_perc+
below_poverty_line_perc + school_count + store_count + (1 | borough),
data = modeling_data,
family = gaussian,
prior_intercept = normal(1600, 20, autoscale = TRUE),
prior = normal(0, 2.5, autoscale = TRUE),
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Mean Rental Price}_{ij} \mid \beta_{0j}, \beta_1, \dots, \beta_k,\sigma_y & \sim N(\mu_{ij}, \sigma_y^2) \; \; \; \text{where } \mu_{ij} = \beta_{0j} + \sum^{11}_{k=1} \beta_{k}X_{ijk} \\ \beta_{0j} & \stackrel{ind}{\sim} N(\beta_0, \sigma_0^2)\\ \beta_{0c} &\sim N(1600, 20^2) \\ \sigma_y &\sim \text{Exp}(1)\\ \sigma_0 &\sim \text{Exp}(1)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &24.1301 34.8009 21.9225 249.6185 0.0325 4.3562 \\ & 5.0098 7.0204 110.1265 1.7160 0.2803 \} \end{align} $$
We chose our prior specifications of mean rental price ($\beta_{0c}$) using Juthi’s experience renting in NYC and a group conversation about typical rental prices we would elect to pay in NYC, Los Angeles, and other major cities we have lived in or around.
pp_check(hi_rent_model)+
xlab("Mean Rental Price") +
labs(title = "Hierarchical Normal Model of \nMonthly Mean Rental Price")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
Our simulations are relatively consistent. However, these simulated distributions are much more variable than the simulated distributions we saw in our non-citizen rent model. Importantly, it also seems our simulated normal posterior distributions had higher variance than what was observed and that is likely because the mean rental prices themselves are not perfectly normally distributed. Theoretically, we could change our likelihood model to adjust for the skew, but for now this is good!
hi_eviction_model <- stan_glmer(
eviction_count ~
transportation_desert_4cat +
total_pop + below_poverty_line_perc+
gini_neighborhood + mean_income + mean_rent +
black_perc + latinx_perc + asian_perc + (1|borough),
data = modeling_data,
family = neg_binomial_2,
chains = 4, iter = 1000*2, seed = 84735, refresh = 0
)
$$ \begin{split} \text{Eviction Count}_{ij} \mid \beta_{0}, \beta_1, ..., \beta_k, r & \sim \text{NegBin}(\mu_{ij}, r) \; \; \; \text{where } \log(\mu_{ij}) = \beta_{0j} + \sum^{11}_{k=1} \beta_{k}X_{ijk} \\ \beta_{0j}\mid \beta_{0}, \sigma_0 & \stackrel{ind}{\sim} N(\beta_0, \sigma_0^2)\\ \beta_{0c} &\sim N(0, 2.5^2) \\ r &\sim \text{Exp}(1)\\ \sigma_0 &\sim \text{Exp}(1)\\ \beta_{k} &\sim N(0,s_k^2) \end{split} $$
$\text{and where}$
$$ \begin{align} s_k \in \{ &5.5004, 7.9328, 4.9972, 0.0001, 25.1032, 56.9002, \\ & 0.0074, 0.5699, 0.9930, 1.1420, 1.6003 \} \end{align} $$
pp_check(eviction_model)+
xlab("Eviction Count") +
xlim(0,2000)+
labs(title = "Negative Binomial Model of \nEviction Count")+
theme(plot.title = element_text(family="DIN Condensed", face="bold", size=25, hjust=.5))
Our simulations of eviction count distributions are dramatically consistent across the iterations. Further, our simulations were relatively consistent with the observed eviction counts. Our negative-binomial model seems to be a pretty good distributional fit, but could certainly be improved upon!
In the following sections, we go through each particular model’s outcome and what they tell us about the relationships between transportation and housing.
non_citizen_clean <- modeling_data %>%
na.omit()%>%
arrange(noncitizen_count)
list <- non_citizen_clean %>%
arrange(noncitizen_count)
set.seed(84735)
predictions_non_citizen <- posterior_predict(
hi_noncit_model, newdata = non_citizen_clean)
ppc_intervals_grouped(
y = list$noncitizen_count,
group = list$borough,
yrep = predictions_non_citizen,
prob_outer = 0.8,
facet_args=list(scales="free")) +
scale_x_continuous(
labels = list$nta_id,
breaks = 1:nrow(list)) +
labs(x = "Neighborhood", y = "Non-Citizen Count")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
tidy(hi_noncit_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
mutate(estimate= ifelse(term == "(Intercept)", exp(estimate), (exp(estimate)-1)*100),
conf.low= ifelse(term == "(Intercept)", exp(conf.low), (exp(conf.low)-1)*100),
conf.high = ifelse(term == "(Intercept)", exp(conf.high), (exp(conf.high)-1)*100))%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Hierarchical Non-Citizen Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 597.5547828 | 0.4842066 | 326.9589636 | 1124.7268543 |
| transportation_desert_4catLimited | 42.9232903 | 0.0994841 | 26.4475522 | 62.3690436 |
| transportation_desert_4catSatisfactory | 49.6544662 | 0.1242106 | 27.3583258 | 75.0465388 |
| transportation_desert_4catExcellent | 53.4648199 | 0.1112574 | 32.5864285 | 77.6980522 |
| total_pop | 0.0025469 | 0.0000016 | 0.0023384 | 0.0027567 |
| mean_income | -0.0760394 | 0.0002402 | -0.1064362 | -0.0450025 |
| mean_rent | 6.3341846 | 0.0171650 | 4.0447755 | 8.7316038 |
| black_perc | 5.8854147 | 0.0154199 | 3.7692499 | 8.0733896 |
| latinx_perc | 12.6987844 | 0.0210003 | 9.6504890 | 15.7287229 |
| asian_perc | 21.6931190 | 0.0250782 | 17.8409547 | 25.7273110 |
Limited Subway Access: When controlling for all other predictors, a neighborhood with limited transit access is expected to have approximately 21.82% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (7.48%, 38.27%) non citizen residents, indicating that neighborhoods with limited transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Satisfactory Subway Access: When controlling for all other predictors, a neighborhood with satisfactory transit access is expected to have approximately 30.22% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (13.99%, 49.09%) non citizen residents, indicating that neighborhoods with satisfactory transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Excellent Subway Access: When controlling for all other predictors, a neighborhood with excellent transit access is expected to have approximately 29.84% more non-citizens than a neighborhood with poor transit access. There’s an 80% probability that this increase could lie anywhere between (13.34%, 48.51%) non citizen residents, indicating that neighborhoods with excellent transit access almost certainly have more non citizen residents than neighborhoods with poor access.
Brooklyn: When controlling for all other predictors, a neighborhood in Brooklyn is expected to have approximately 16.61% more non-citizens than a neighborhood in the Bronx. There’s an 80% probability that this increase could lie anywhere between (1.68%, 34.07) non citizen residents, indicating that neighborhoods in Brooklyn almost certainly have more non citizen residents than the Bronx, but the magnitude of this increase may vary.
Manhattan: When controlling for all other predictors, a neighborhood in Manhattan is expected to have approximately 20.58% more non-citizens than in the Bronx. There’s an 80% probability that this increase could lie anywhere between (2.268, 42.85) non citizen residents, indicating that neighborhoods in Manhattan almost certainly have more non citizen residents than the Bronx.
Mean Income: When controlling for all other predictors, a 100 dollar increase in mean neighborhood income is associated with approximately a 0.0793% decrease in non citizen count. However, there is a 80% chance that the decrease in non citizen count may be any value between (0.1102, 0.0476), indicating that there is almost certainly a negative relationship between mean income and non citizen count, but its magnitude may vary.
Mean Rent: When controlling for all other predictors, a 100 dollar increase in mean neighborhood rent is associated with approximately a 6.29% increase in non citizen counts. However, there is an 80% chance that the increase in non citizen count may be any value between (3.96%, 8.68%), indicating that there is almost certainly a positive relationship between mean rent and non citizen count, but its magnitude may vary.
Black Percentage: When controlling for all other predictors, a 10% increase in the Black population in a neighborhood is associated with approximately a 5.20% increase in non citizen counts. However, there is an 80% chance that the increase in non citizen count may be any value between (2.99%, 7.45%), indicating that there is almost certainly a positive relationship between Black resident percentage and non citizen count, but its magnitude may vary.
Latinx Percentage: When controlling for all other predictors, a 10% increase in the Latinx population in a neighborhood is associated with approximately a 13.46% increase in non citizen count. However, there is an 80% chance that the increase in non citizen count may be any value between (10.08%, 17.07%), indicating that there is almost certainly a positive relationship between Latinx resident percentage and non citizen count, but its magnitude may vary.
Asian Percentage: When controlling for all other predictors, a 10% increase in the Asian population in a neighborhood is associated with approximately a 19.63% increase in non citizen count. However, there is an 80% chance that the increase in non citizen count may be any value between (15.75%, 23.69%), indicating that there is almost certainly a positive relationship between Asian resident percentage and non citizen count, but its magnitude may vary.
rent_clean <- modeling_data %>%
na.omit()%>%
arrange(mean_rent)
list <- rent_clean %>%
arrange(mean_rent)
set.seed(84735)
predictions_rent <- posterior_predict(
hi_rent_model, newdata = rent_clean)
ppc_intervals_grouped(
y = list$mean_rent,
group = list$borough,
yrep = predictions_rent,
prob_outer = 0.8,
facet_args=list(scales="free")) +
scale_x_continuous(
labels = list$nta_id,
breaks = 1:nrow(list)) +
labs(x = "Neighborhood", y = "Mean Rental Price (100$)")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
tidy(hi_rent_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Hierarchical Rent Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 7.5599854 | 1.9174175 | 5.0744949 | 10.1273778 |
| transportation_desert_4catSatisfactory | 0.7325156 | 0.5450339 | 0.0111175 | 1.4017415 |
| mean_income | 0.0123040 | 0.0007627 | 0.0113063 | 0.0132936 |
| black_perc | -0.0889752 | 0.0693227 | -0.1824206 | -0.0009446 |
| asian_perc | 0.2452884 | 0.1143663 | 0.1053215 | 0.3902625 |
| school_count | -0.0388724 | 0.0279439 | -0.0737347 | -0.0049112 |
For rent model:
Store Count: When controlling for all other predictors, as grocery store and food vendor counts in a neighborhood increase by 1, rent increases by approximately $1.049 dollars. However, there is a 80% chance that the increase associated with store count may be any value between (0.307, 1.799) dollars, indicating that there is almost certainly a positive relationship between store count and rent, but its magnitude may vary slightly.
Mean Income: When controlling for all other predictors, a 100 dollar increase in mean neighborhood income is associated with approximately a $1.20 increase in rent. However, there is a 80% chance that the increase associated with rental price increases may be any value between (1.129, 1.284) dollars, indicating that there is almost certainly a positive relationship between mean income and mean rental prices, but its magnitude may vary slightly.
Black Percentage: When controlling for all other predictors, a 10% increase in the black proportion of a neighborhood is associated with approximately a $10.20 decrease in rent. However, there is an 80% chance that the decrease associated with rent may be any value between (19.36, 0.685) dollars, indicating that there is almost certainly a negative relationship between black resident percentage and rent, but its magnitude may vary.
Asian Percentage: When controlling for all other predictors, a 10% increase in the Asian population in a neighborhood is associated with approximately a $20.52 increase in rent. However, there is an 80% chance that the increase associated with rent may be any value between (5.763, 34.87), indicating that there is almost certainly a positive relationship between Asian resident percentage and rent, but its magnitude may vary greatly.
eviction_clean <- modeling_data %>%
na.omit()%>%
arrange(eviction_count)
list <- eviction_clean %>%
as.tibble() %>%
arrange(eviction_count)
set.seed(454)
predictions_eviction <- posterior_predict(
hi_eviction_model, newdata = eviction_clean)
ppc_intervals_grouped(
y = list$eviction_count,
group = list$borough,
yrep = predictions_eviction,
prob_outer = 0.8,
facet_args=list(scales="free")) +
scale_x_continuous(
labels = eviction_clean$nta_id,
breaks = 1:nrow(eviction_clean)) +
labs(x = "Neighborhood", y = "Eviction Counts")+
xaxis_text(angle = -70, vjust = 1, hjust = 0)+
theme_linedraw() +
theme(panel.grid.minor = element_line("transparent"),
panel.grid.major.x = element_line("transparent"),
axis.text.x = element_blank(),
plot.title = element_text(family="DIN Condensed", size = 30, hjust=.5, face = "bold"),
strip.background.x = element_rect(fill="Black", color="Black"),
strip.text.x = element_text(size = 30,
color = "White",
face = "bold"))
tidy(hi_eviction_model, effects = "fixed", conf.int = TRUE, conf.level = 0.8)%>%
mutate(estimate= ifelse(term == "(Intercept)", exp(estimate), (exp(estimate)-1)*100),
conf.low= ifelse(term == "(Intercept)", exp(conf.low), (exp(conf.low)-1)*100),
conf.high = ifelse(term == "(Intercept)", exp(conf.high), (exp(conf.high)-1)*100))%>%
filter(conf.low > 0 & conf.high > 0 | conf.low < 0 & conf.high < 0) %>%
kable(align = "c", caption = "Eviction Model - Summary") %>%
kable_styling()
| term | estimate | std.error | conf.low | conf.high |
|---|---|---|---|---|
| (Intercept) | 12.1770475 | 0.7077719 | 4.9625655 | 31.5700661 |
| transportation_desert_4catLimited | 56.3358592 | 0.1098827 | 35.0321649 | 78.8037987 |
| transportation_desert_4catSatisfactory | 59.0565859 | 0.1324513 | 33.7288567 | 90.6827403 |
| transportation_desert_4catExcellent | 58.4466870 | 0.1292019 | 34.5915116 | 86.8017691 |
| total_pop | 0.0022117 | 0.0000019 | 0.0019652 | 0.0024441 |
| gini_neighborhood | 1650.3602914 | 1.4388537 | 173.7487664 | 10592.1224393 |
| mean_income | -0.1229627 | 0.0003220 | -0.1648691 | -0.0823271 |
| mean_rent | 4.3859623 | 0.0190370 | 1.9148599 | 7.0029312 |
| black_perc | 18.3424533 | 0.0190159 | 15.3962735 | 21.1737211 |
| latinx_perc | 8.5471072 | 0.0325274 | 4.1179334 | 13.0518350 |
After removing predictors whose 80% credible intervals included the possibility of non-effect when controlling for other covariates, we found that there were 13 remaining predictors of an arbitrary neighborhood’s eviction counts. In the following list, categorical predictors’ classes were listed together:
In the following section, we interpret each predictor. However, we included total population to control for eviction count’s incidence relative to neighborhood population. As such, we will not interpret its specific \(\beta\) value.
Next, we interpret each predictor:
table1 <- prediction_summary(model=noncit_model, data=modeling_data) %>%
mutate(Model = "Non-Hierarchical")
table2 <- prediction_summary(model=hi_noncit_model, data=modeling_data) %>%
mutate(Model = "Hierarchical")
rbind(table1, table2) %>%
dplyr::mutate(model = Model, .before=1) %>%
dplyr::select(-Model)%>% kable() %>% kable_styling()
| model | mae | mae_scaled | within_50 | within_95 |
|---|---|---|---|---|
| Non-Hierarchical | 1026.946 | 0.5670020 | 0.5666667 | 0.9666667 |
| Hierarchical | 1036.095 | 0.5555193 | 0.5555556 | 0.9666667 |
Using in-sample scaled MAE, it’s evident that the differences between our two negative binomial models of non-citizen counts were minute In other settings, we would typically recommend to use cross-validated error metrics to truly compare these models. However, because we are comparing a hierarchical model to a non-hierarchical model, cross-validation works slightly differently. In the former case, cross-validation via the prediction_summary_cv function in bayesrules makes data permutations to represent a “new borough”, rather than a set of arbitrary models. To circumvent these differences, we use the expected-log predictive density (ELPD) of each respective model to compare the performance of each model. The details of this approach can be found here.
mod1_elpd <- loo(noncit_model)
hi_mod1_elpd <- loo(hi_noncit_model)
# Compare the ELPD for our 2 models
loo_compare(mod1_elpd, hi_mod1_elpd) %>%
kable(caption = "Non-Citizen Count EPLD Metrics", align="c") %>%
kable_styling()
| elpd_diff | se_diff | elpd_loo | se_elpd_loo | p_loo | se_p_loo | looic | se_looic | |
|---|---|---|---|---|---|---|---|---|
| hi_noncit_model | 0.0000000 | 0.0000000 | -1603.686 | 11.69514 | 13.74279 | 2.572952 | 3207.373 | 23.39029 |
| noncit_model | -0.7008571 | 0.6682885 | -1604.387 | 11.59500 | 14.55443 | 2.396960 | 3208.775 | 23.19000 |
From the above ELPD rankings, it seems that the non-hierarchical model of non-citizen counts performed better than its hierarchical parallel. Explicitly, there was a decrease of .536 standard deviations when comparing the non-hiearchical to its hiearchical parallel.
noncit_resid <- modeling_data %>%
mutate(resid = noncit_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#5E76AD") +
theme_minimal() +
ggtitle("Non-Hierarchical Model:\nNon-Citizen Count Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
hi_noncit_resid <- modeling_data %>%
mutate(resid = hi_noncit_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#5E76AD") +
theme_minimal() +
ggtitle("Hierarchical Model:\nNon-Citizen Count Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
ggarrange(noncit_resid, hi_noncit_resid, ncol=2, nrow=1)
The residuals on our hierarchical model are not perfectly randomly distributed across all neighborhoods in NYC, but the scale of these residuals is much smaller than the non-hierarchical model. One could also make the case that there are slight over predictions (darker blue) of non-citizen counts in the Brooklyn (bottom left) for the non-hierarchical model. However, these differences are mostly negligible.
waic_tab1 <- waic(noncit_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Non-Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
waic_tab2 <-waic(hi_noncit_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
rbind(waic_tab1, waic_tab2) %>%
kable() %>% kable_styling()
| Model | WAIC | SE |
|---|---|---|
| Non-Hierarchical | 3208.463 | 23.15916 |
| Hierarchical | 3206.880 | 23.22938 |
Our last error metric of non-citizen counts is the Watanabe–Akaike information criterion (WAIC). When comparing two models with the WAIC, the better predicting model would be the model with the smaller WAIC value. Here, it seems that non-hierarchical model of non-citizen counts has the lowest WAIC, but the difference is largely minimal. Altogether, we choose the hierarchical model of non-citizen counts given its lower ELPD, WAIC, and spatial residual patterning.
table1 <- prediction_summary(model=rent_model, data=modeling_data) %>%
mutate(Model = "Non-Hierarchical")
table2 <- prediction_summary(model=hi_rent_model, data=modeling_data) %>%
mutate(Model = "Hierarchical")
rbind(table1, table2) %>%
dplyr::mutate(model = Model, .before=1) %>%
dplyr::select(-Model)%>% kable() %>% kable_styling()
| model | mae | mae_scaled | within_50 | within_95 |
|---|---|---|---|---|
| Non-Hierarchical | 0.8377195 | 0.5259208 | 0.6055556 | 0.9500000 |
| Hierarchical | 0.8024302 | 0.5087840 | 0.5888889 | 0.9444444 |
Once again when using in-sample scaled MAE, the differences between our two normal-normal models of mean rental prices were largely minimal. Our predictions of rental price in both models were about 80 dollars away from their observed rental prices. However, the scaled mean absolute error metrics in the hierarchical model indicate that across simulations the observed value is about 0.3 standard deviations away from their the medians of the posterior predictive distributions of rental prices. This is a nontrivial improvement from the .5 standard deviation in the case of the non-hierarchical distribution. Once again, we use ELPD metrics to formally decided between the two models.
mod1_elpd <- loo(rent_model)
hi_mod1_elpd <- loo(hi_rent_model)
# Compare the ELPD for our 2 models
loo_compare(mod1_elpd, hi_mod1_elpd) %>%
kable(caption = "Mean Rental Price EPLD Metrics", align="c") %>%
kable_styling()
| elpd_diff | se_diff | elpd_loo | se_elpd_loo | p_loo | se_p_loo | looic | se_looic | |
|---|---|---|---|---|---|---|---|---|
| hi_rent_model | 0.000000 | 0.0000000 | -340.4415 | 14.97455 | 16.67414 | 3.558889 | 680.8830 | 29.94909 |
| rent_model | -2.194559 | 0.6438043 | -342.6361 | 14.82936 | 18.33416 | 3.689465 | 685.2721 | 29.65871 |
From the above ELPD rankings, it seems that the hierarchical model of mean neighborhood rental prices performed better than its non-hierarchical parallel.
rent_resid <- modeling_data %>%
mutate(resid = rent_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#30969C") +
theme_minimal() +
ggtitle("Non-Hierarchical Model:\nMean Rental Price Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
hi_rent_resid <- modeling_data %>%
mutate(resid = hi_rent_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#30969C") +
theme_minimal() +
ggtitle("Hierarchical Model:\nMean Rental Price Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
ggarrange(rent_resid, hi_rent_resid, ncol=2, nrow=1)
In the case of the non-hierarchical model, the distribution of our residuals indicate that our model’s mispredictions are randomly distributed. Further, our residuals in the non-hiearchical model are relatively small when compared to the hierarcichal model. Tthe hierarcichal model must be addressed. In the hiearchical model grouped by borough there is a clear indication of systematic mispredictions that appear distributed by borough. Crucially, it seems that we are systematically overpredicting rental prices in both Queens (bottom right) and Brooklyn (bottom left), but with greater overprediction occurring for Brooklyn.
waic_tab1 <- waic(rent_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Non-Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
waic_tab2 <-waic(hi_rent_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
rbind(waic_tab1, waic_tab2) %>%
kable() %>% kable_styling()
| Model | WAIC | SE |
|---|---|---|
| Non-Hierarchical | 684.9805 | 29.67027 |
| Hierarchical | 680.4569 | 29.84038 |
It seems that hierarchical model of rental prices has the lowest WAIC, but the difference is largely minimal. The hierarchical model’s residual patterning, ELPD metric, in-sample residual patterns, and WAIC all indicate that the hierarchical version may be more appropriate.
table1 <- prediction_summary(model=eviction_model, data=modeling_data) %>%
mutate(Model = "Non-Hierarchical")
table2 <- prediction_summary(model=eviction_model, data=modeling_data) %>%
mutate(Model = "Hierarchical")
rbind(table1, table2) %>%
dplyr::mutate(model = Model, .before=1) %>%
dplyr::select(-Model)%>% kable() %>% kable_styling()
| model | mae | mae_scaled | within_50 | within_95 |
|---|---|---|---|---|
| Non-Hierarchical | 42.28500 | 0.5461398 | 0.5777778 | 0.9555556 |
| Hierarchical | 43.08787 | 0.5467191 | 0.5777778 | 0.9555556 |
Once again when using in-sample scaled MAE, the differences between our two negative-binomial models of evictions count were largely minimal. Our predictions of eviction counts in both models were about 40 cases away from their observed counts and with very similar scaled MAE metrics. Typically, we’d suggest the use of the non-hierarchical model given that the performance is so similar and the computational burden of a hierarchical model is no longer warranted.
mod1_elpd <- loo(eviction_model)
hi_mod1_elpd <- loo(hi_eviction_model)
# Compare the ELPD for our 2 models
loo_compare(mod1_elpd, hi_mod1_elpd) %>%
kable(caption = "Eviction Count EPLD Metrics", align="c") %>%
kable_styling()
| elpd_diff | se_diff | elpd_loo | se_elpd_loo | p_loo | se_p_loo | looic | se_looic | |
|---|---|---|---|---|---|---|---|---|
| hi_eviction_model | 0.0000000 | 0.0000000 | -1051.930 | 13.74662 | 16.95747 | 2.781855 | 2103.86 | 27.49324 |
| eviction_model | -0.0950349 | 0.5368605 | -1052.025 | 13.84190 | 17.51510 | 2.923380 | 2104.05 | 27.68380 |
From the above ELPD rankings, it also seems that the hierarchical model of eviction counts performed better than its non-hierarchical parallel. Next, we will compare how these 2 models’ residuals are spatially distributed.
evict_resid <- modeling_data %>%
mutate(resid = eviction_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#C47572") +
theme_minimal() +
ggtitle("Non-Hierarchical Model:\nEviction Count Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
hi_evict_resid <- modeling_data %>%
mutate(resid = hi_eviction_model$residuals) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#C47572",
guide = guide_legend(title = "Residual")) +
theme_minimal() +
ggtitle("Hierarchical Model:\nEviction Count Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
ggarrange(evict_resid, hi_evict_resid, ncol=2, nrow=1)
Our residuals are randomly distributed across all neighborhoods indicating that our model’s bias is consistent across observations— this is really good! One could make the case that there are slight under predictions (darker red) of eviction counts in the Bronx (top) for both models. However, these patterns are relatively minute.
waic_tab1 <- waic(eviction_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Non-Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
waic_tab2 <-waic(hi_eviction_model)$estimates%>%
as.data.frame() %>%
rownames_to_column() %>%
as.tibble()%>%
filter(rowname=="waic") %>%
dplyr::select(-c(rowname)) %>%
mutate(Model = "Hierarchical", .before=1) %>%
dplyr::rename(WAIC = Estimate)
rbind(waic_tab1, waic_tab2) %>%
kable() %>% kable_styling()
| Model | WAIC | SE |
|---|---|---|
| Non-Hierarchical | 2103.173 | 27.53465 |
| Hierarchical | 2103.144 | 27.38933 |
It seems that hierarchical model of rental prices has the lowest WAIC, but only by .03 units. But given the hierarchical model’s residual patterning, ELPD metric, in-sample residual patterns, and WAIC we select the hierarchical model of eviction counts.
We’ve confirmed that even after adjusting for income, rental prices, income inequality, and borough differences, neighborhoods in NYC with a substantial proportion of Black and Latinx residents are experiencing dramatic increased risks of eviction. Interestingly, when accounting for economic and demographic predictors, the relationships with transportation we expected to see were reversed. That is, increased transportation access was associated with more evictions. This could be related to the increased population sizes in areas with the best access to transportation (e.g. Manhattan) or it could be because the disparities that transportation inaccess reflects (e.g. racial and class-based tensions) have been accounted for.
Importantly, we found that there was statistically significant spatial clustering of both eviction counts and mean rental prices using Moran’s I from the spdep package.
library(spdep)
modeling_data <- modeling_data %>%
st_as_sf()
col_sp <- as(modeling_data, "Spatial")
col_nb <- poly2nb(col_sp) # queen neighborhood
col_listw <- nb2listw(col_nb, style = "B") # listw version of the neighborhood
W <- nb2mat(col_nb, style = "B") # binary structure
evict_moran <- tidy(moran.mc(col_sp$eviction_count, listw = col_listw, nsim = 999, alternative = "greater")) %>%
mutate(Term = "Eviction", .before=1)
rent_moran <- tidy(moran.mc(col_sp$mean_rent, listw = col_listw, nsim = 999, alternative = "greater")) %>%
mutate(Term = "Mean Rent", .before=1)
rbind(rent_moran, evict_moran) %>%
kable() %>%
kable_styling()
| Term | statistic | p.value | parameter | method | alternative |
|---|---|---|---|---|---|
| Mean Rent | 0.6560430 | 0.001 | 1000 | Monte-Carlo simulation of Moran I | greater |
| Eviction | 0.5794612 | 0.001 | 1000 | Monte-Carlo simulation of Moran I | greater |
Our results are then likely biased by the spatial relationships between neighborhoods. As such, we could extend this work to the spatial domain using methods from the CARBayes or INLA packages. Following work by Katie Jolly and Raven McKnight, we have outlined a spatial workflow for both the eviction and rental price models using CARBayes in the appendix. However, because spatial models were beyond the scope of this project and class, we’d like to emphasize that in a more detailed analysis the models we outline in the appendix would likely be adjusted in STAN or CARBayes to use different likelihoods, spatial effect priors (e.g. BYM, Intrinsic CAR, etc), and different priors for the predictors’ coefficients. Further, in a more detailed analysis, we would explicitly describe the mathematical construction of the models.
Although a lot of work went into designing models with causal blocking and confounding in mind, our models remain imperfect. Some major limitations involved the encoding of transportation deserts and the presence of unmeasured confounders.Because we may not have not accounted for all structural predictors in housing equity such as a neighborhood’s rent control policies nor have we adjusted for the reasons behind eviction, we cannot be entirely confident about our models’ conclusions.
Across our models, it becomes clear that many of the structural housing and demographic issues present in NYC need to be more rigorously addressed by both policy-makers and its citizens, regardless of these particular models’ performance. Health begins at home. And if NYC’s Black and Latinx residents are being crushed under the fist of inequity and consequently experiencing increased risks of eviction or tenuous rental prices, then it becomes a health imperative to critically and revolutionarily address NYC’s housing system.
Knowing that there is spatial clustering mean rental prices , we fit a normal model with weakly informative priors for the \(\beta_k\), our scaled prior intercept \(N(1600, 20^2)\), and Besag prior for a random spatial effect via the CARBayes package’s S.CARleroux function. If there was a non-constant spatial effect on rental prices in a neighborhood, we would edit the rho parameter below to approximate this new spatial effect prior called a Leroux.
library(CARBayes)
equation <- mean_rent ~ total_pop +
transportation_desert_4cat + borough + gini_neighborhood +
mean_income + black_perc + latinx_perc + asian_perc+
below_poverty_line_perc + school_count + store_count
carbayes_rent <- S.CARleroux(equation,
data = modeling_data,
W = W, family = "gaussian",
prior.mean.beta = c(1600, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
prior.var.delta = c(20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
burnin = 20000, n.sample = 100000, rho=1,
thin = 10, verbose=F)
tidy(moran.mc(x = as.vector(carbayes_rent$residuals$response), listw = col_listw, nsim = 9999, alternative = "greater")) %>%
mutate(Term = "Residual", .before=1) %>%
kable(caption ="Residual Clustering - Rent") %>%
kable_styling()
| Term | statistic | p.value | parameter | method | alternative |
|---|---|---|---|---|---|
| Residual | -0.0075518 | 0.5022 | 4978 | Monte-Carlo simulation of Moran I | greater |
Non-significant Moran I clustering of residuals indicates that our residuals of rental prices are uniformly distributed across neighborhoods. Therefore, this spatial model is sufficiently built to study these rental price trends.
t(carbayes_rent$modelfit)%>%
as.tibble() %>%
kable(align = "c", caption = "CARBayes Spatial Rent Model - DIC Metrics") %>%
kable_styling()
| DIC | p.d | WAIC | p.w | LMPL | loglikelihood |
|---|---|---|---|---|---|
| 658.7775 | 39.45344 | 671.5902 | 44.40482 | -340.1351 | -289.9353 |
Our WAIC metrics for this spatial model is slightly better than the best of our non-spatial models (Difference = 9.4086). Once again, in a more detailed analysis we could edit our spatial effect prior.
round(carbayes_rent$summary.results[, 1:7], 4) %>%
as.data.frame() %>%
rownames_to_column() %>%
rename(term = rowname) %>%
as.tibble() %>%
mutate(`Median`= ifelse(term == "(Intercept)", exp(`Median`), (exp(`Median`)-1)*100),
`2.5%`= ifelse(term == "(Intercept)", exp(`2.5%`), (exp(`2.5%`)-1)*100),
`97.5%` = ifelse(term == "(Intercept)", exp(`97.5%`), (exp(`97.5%`)-1)*100))%>%
filter(`2.5%` > 0 & `97.5%` > 0 | `2.5%` < 0 & `97.5%` < 0) %>%
mutate_if(is.numeric, ~round(., 4)) %>%
kable(align = "c", caption = "CARBayes Spatial Rent Model - Summary") %>%
kable_styling()
| term | Median | 2.5% | 97.5% | n.sample | % accept | n.effective | Geweke.diag |
|---|---|---|---|---|---|---|---|
| (Intercept) | 7613.6655 | 28.2389 | 2448289.0705 | 8000 | 100 | 1847.2 | -4.3 |
| mean_income | 1.1668 | 0.9949 | 1.3490 | 8000 | 100 | 957.3 | 4.8 |
| nu2 | 526.0750 | 209.1016 | 1313.1410 | 8000 | 100 | 86.2 | 3.2 |
| tau2 | 107.6741 | 0.4108 | 1628.9511 | 8000 | 100 | 101.3 | -3.7 |
| rho | 171.8282 | 171.8282 | 171.8282 | NA | NA | NA | NA |
Here, the only significant predictor of is mean income which is positively associated with increased rental prices.
modeling_data %>%
mutate(resid = carbayes_rent$residuals$response) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#30969C",
guide = guide_legend(title = "Residuals")) +
theme_minimal() +
ggtitle("CARBayes Besag:\nMean Rental Price Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
Our Besag model residuals look very evenly distributed!
We fit a Besag model using a Poisson likelihood to study eviction counts across New York.
library(CARBayes)
equation <- eviction_count ~ offset(log(total_pop)) +
transportation_desert_4cat + borough +
below_poverty_line_perc + gini_neighborhood + mean_income + mean_rent+
black_perc + latinx_perc + asian_perc
carbayes_evictions <- S.CARleroux(equation,
data = modeling_data,
W = W, family = "poisson",
burnin = 200000, n.sample = 1000000, rho=1,
thin = 10, verbose=F)
tidy(moran.mc(x = as.vector(carbayes_evictions$residuals$response), listw = col_listw, nsim = 9999, alternative = "greater")) %>%
mutate(Term = "Residual", .before=1) %>%
kable(caption ="Residual Clustering - Evictions") %>%
kable_styling()
| Term | statistic | p.value | parameter | method | alternative |
|---|---|---|---|---|---|
| Residual | -0.2174898 | 0.9999 | 1 | Monte-Carlo simulation of Moran I | greater |
We found no residual clustering! The plot below shows them spatially.
modeling_data %>%
mutate(resid = carbayes_evictions$residuals$response) %>%
ggplot() +
geom_sf(aes(fill = resid), color = "#8f98aa")+
scale_fill_gradient(low = "#FCF5EE", high = "#C47572",
guide = guide_legend(title = "Number of Evictions")) +
theme_minimal() +
ggtitle("CARBayes Besag:\nEviction Count Residuals ")+
theme(axis.text = element_blank(),
panel.grid.major = element_line("transparent"),
plot.title = element_text(family="DIN Condensed", size = 2* 25, face = "bold"),
legend.key.width = unit(.5, "in"),
legend.title = element_text(size = 20, face="bold", family="DIN Condensed"),
legend.position = "bottom" ,
legend.text = element_text(size = 15, face="bold", family="DIN Condensed"))+
guides(fill = guide_colourbar(title = "Residual Error", title.position="top", title.hjust = 0.5))
Our residuals look fantastic! Woohoo!
Our WAIC metrics for this spatial model on eviction counts is dramatically better than the best of our non-spatial models (Difference = 501.104), indicating that this a much better fit to our data than our previous models.
t(carbayes_evictions$modelfit)%>%
as.tibble() %>%
kable(align = "c", caption = "CARBayes Spatial Eviction Model - DIC Metrics") %>%
kable_styling()
| DIC | p.d | WAIC | p.w | LMPL | loglikelihood |
|---|---|---|---|---|---|
| 1640.26 | 168.8126 | 1601.79 | 93.86563 | -901.9265 | -651.3177 |
round(carbayes_evictions$summary.results[, 1:7], 4) %>%
as.data.frame() %>%
rownames_to_column() %>%
rename(term = rowname) %>%
as.tibble() %>%
mutate(`Median`= ifelse(term == "(Intercept)", exp(`Median`), (exp(`Median`)-1)*100),
`2.5%`= ifelse(term == "(Intercept)", exp(`2.5%`), (exp(`2.5%`)-1)*100),
`97.5%` = ifelse(term == "(Intercept)", exp(`97.5%`), (exp(`97.5%`)-1)*100))%>%
filter(`2.5%` > 0 & `97.5%` > 0 | `2.5%` < 0 & `97.5%` < 0) %>%
mutate_if(is.numeric, ~round(., 4)) %>%
kable(align = "c", caption = "CARBayes Spatial Eviction Model - Summary") %>%
kable_styling()
| term | Median | 2.5% | 97.5% | n.sample | % accept | n.effective | Geweke.diag |
|---|---|---|---|---|---|---|---|
| (Intercept) | 0.0004 | 0.0001 | 0.0017 | 80000 | 43 | 276.6 | -0.9 |
| below_poverty_line_perc | -75.3058 | -93.1409 | -9.1445 | 80000 | 43 | 278.6 | 1.1 |
| gini_neighborhood | 6134.6030 | 323.6765 | 119208.7782 | 80000 | 43 | 294.9 | 0.3 |
| mean_income | -0.1299 | -0.1798 | -0.0800 | 80000 | 43 | 155.7 | 0.0 |
| mean_rent | 5.4641 | 2.4290 | 8.8282 | 80000 | 43 | 249.5 | 0.0 |
| black_perc | 20.7799 | 16.0905 | 26.1246 | 80000 | 43 | 348.2 | -0.5 |
| latinx_perc | 14.0880 | 8.5456 | 20.4663 | 80000 | 43 | 265.9 | 1.6 |
| tau2 | 42.6751 | 32.4851 | 57.3339 | 80000 | 100 | 7235.7 | 1.9 |
| rho | 171.8282 | 171.8282 | 171.8282 | NA | NA | NA | NA |
Although this model has performed phenomenally, we could likely improve this model by choosing a different family for our regression. In NYC, neighborhood eviction counts are zero-inflated, so a count regression model that allows for increased variance or zero-inflation— like Negative-Binomial (NB) or Zero-Inflated Poisson (ZIP) regression— could improve this analysis. Unfortunately, CARBayes does not support such regressions. INLA is a good computational alternative. INLA is a computationally efficient modeling alternative to MCMC based methods— like those in CARBayes or STAN— that use numerical integration by way of Laplace approximations to estimate the posterior distributions. The key difference is that INLA can approximate what MCMC does, but without any sampling or simulation. Beyond its computational efficiency, it’s important to note that INLA supports spatial models using both ZIP and NB data distributions.